package com.nageoffer.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nageoffer.shortlink.project.dao.entity.LinkStatsTodayDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

public interface LinkStatsTodayMapper extends BaseMapper<LinkStatsTodayDO> {

    /**
     * 短链接监控今日数据
     * @param linkStatsTodayDO
     */
    @Insert("INSERT INTO t_link_stats_today (" +
            "gid, full_short_url, date, today_pv, today_uv, today_uip, create_time, update_time, del_flag" +
            ") VALUES (" +
            "#{linkStatsTodayDo.gid}, " +
            "#{linkStatsTodayDo.fullShortUrl}, " +
            "#{linkStatsTodayDo.date}, " +
            "#{linkStatsTodayDo.todayPv}, " +
            "#{linkStatsTodayDo.todayUv}, " +
            "#{linkStatsTodayDo.todayUip}, " +
            "now(), " +  // create_time 用当前时间
            "now(), " +  // update_time 用当前时间
            "0" +  // del_flag
            ") ON DUPLICATE KEY UPDATE " +
            "today_pv = today_pv + #{linkStatsTodayDo.todayPv}, " +  // 下划线字段名，与数据库一致
            "today_uv = today_uv + #{linkStatsTodayDo.todayUv}, " +
            "today_uip = today_uip + #{linkStatsTodayDo.todayUip}, " +
            "update_time = now()")  // 更新时刷新时间
    void shortLinkTodayStats(@Param("linkStatsTodayDo") LinkStatsTodayDO linkStatsTodayDO);
}
